import 'package:flutter/material.dart';

extension CUContextExtends on BuildContext {
  MediaQueryData get mq => MediaQuery.of(this);

  Size get mqSize => mq.size;

  EdgeInsets get mqPadding => mq.padding;

  EdgeInsets get mqViewInsets => mq.viewInsets;

  double get widthMq => mqSize.width;

  double get heightMq => mqSize.height;

  double get statusBarHeight => mqPadding.top;

  double get bottomBarHeight => mqPadding.bottom;

  //输入法高度
  double get keyboardHeight => mqViewInsets.bottom;

  //取消焦点
  void unfocus() {
    FocusScope.of(this).unfocus();
  }

  ThemeData get themeOf => Theme.of(this);

  bool get isDark => (themeOf.brightness == Brightness.dark);

  Color? get iconThemeColor => themeOf.iconTheme.color;

  TextTheme get themeText => themeOf.textTheme;

  Orientation get orientationMq => mq.orientation;

  ///检查设备是否处于横向模式
  bool get isLandscapeMq => orientationMq == Orientation.landscape;

  ///检查设备是否处于纵向模式
  bool get isPortraitMq => orientationMq == Orientation.portrait;

  double get dpr => MediaQuery.of(this).devicePixelRatio;

  TextScaler get textScaler => MediaQuery.of(this).textScaler;

  /// 从屏幕上获取最短的边
  double get mqShortestSide => mqSize.shortestSide;

  /// 如果宽度大于800，则为True
  bool get showNavbar => (widthMq > 800);

  /// 如果最短边小于600p，则为True
  bool get isPhone => (mqShortestSide < 600);

  /// 如果最短边大于600p，则为True
  bool get isSmallTablet => (mqShortestSide >= 600);

  /// 如果最短边大于720p，则为True
  bool get isLargeTablet => (mqShortestSide >= 720);

  /// 如果当前设备是平板电脑，则为True
  bool get isTablet => isSmallTablet || isLargeTablet;
}
